package touro.finances.gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import touro.finances.control.AddExpenseController;
import touro.finances.model.FinancesDatabase;

public class ExpensesPanel extends JPanel{

	private JLabel amountL, dateL, descriptionL, typeL, locationL;
	private JTextField amountT, dateT, locationT;
	private JTextArea descriptionT;
	private JComboBox typeC;
	private JButton save;
	private FinancesDatabase fd;
	
	public ExpensesPanel(FinancesDatabase fd){
		this.fd = fd;
		this.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();		

		amountL = new JLabel("Amount:");
		amountL.setHorizontalAlignment(SwingConstants.RIGHT);
		dateL = new JLabel("Date:");
		dateL.setHorizontalAlignment(SwingConstants.RIGHT);
		typeL = new JLabel("Type:");
		typeL.setHorizontalAlignment(SwingConstants.RIGHT);
		descriptionL = new JLabel("Description:");
		descriptionL.setHorizontalAlignment(SwingConstants.RIGHT);
		locationL = new JLabel("Location:");
		locationL.setHorizontalAlignment(SwingConstants.RIGHT);
		
		amountT = new JTextField(10);
		dateT = new JTextField(10);
		locationT = new JTextField(10);
		descriptionT = new JTextArea(4, 20);
		descriptionT.setLineWrap(true);
		descriptionT.setWrapStyleWord(true);
		//get types from db
		typeC = new JComboBox();
		
		save = new JButton("Save");
		save.addActionListener(new AddExpenseController(this, fd));
		
		//c.anchor = GridBagConstraints.FIRST_LINE_START;
		c.insets = new Insets(7,5,7,5);
		c.fill = GridBagConstraints.HORIZONTAL;
		
		c.gridx = 0;
		c.gridy = 0;
		add(amountL, c);
		c.gridy = 1;
		add(dateL, c);
		c.gridy = 2;
		add(typeL, c);
		c.gridy = 3;
		add(locationL, c);
		c.gridy=4;
		add(descriptionL, c);
		
		//c.anchor = GridBagConstraints.LINE_START;
		c.gridx=1;
		c.gridy=0;
		add(amountT, c);
		c.gridy=1;
		add(dateT, c);
		c.gridy=2;
		add(typeC, c);
		c.gridy=3;
		add(locationT, c);
		c.gridy=4;
		add(descriptionT, c);
		
		c.gridx = 0;
		c.gridwidth = 2;
		c.gridy = 5;
		c.fill = GridBagConstraints.NONE;
		c.anchor = GridBagConstraints.PAGE_END;
		add(save, c);	
	}

	public String getAmount() {
		return amountT.getText();
	}

	public void setAmount(String amount) {
		this.amountT.setText(amount);
	}

	public String getDate() {
		return dateT.getText();
	}

	public void setDate(String date) {
		this.dateT.setText(date);
	}

	public String getLocationT() {
		return locationT.getText();
	}

	public void setLocationT(String location) {
		this.locationT.setText(location);
	}

	public String getDescription() {
		return descriptionT.getText();
	}

	public void setDescription(String description) {
		this.descriptionT.setText(description);
	}

	public Object getType() {
		return typeC.getSelectedItem();
	}

	public void setType(Object type) {
		this.typeC.setSelectedItem(type);
	}
	
	
	
	

}
